<template>
  <view class="content">
    <view class="btn">
      <button class="new" type="primary" @click="handleAdd">添加卸货地</button>
    </view>
    <view class="content-box">
      <navigator
        class="item-box-ng"
        v-for="(item, index) in lists"
        :url="`/packageB/pages/common/unloader-editing/index?id=${item.id}`"
        hover-class="navigator-hover"
      >
        <view class="item-box">
          <text class="status">
            <text class="isnotReal">卸</text>
          </text>
          <text class="cph1">{{ item.cusAddress }}</text>
          <uni-icons type="forward" size="20"></uni-icons>
        </view>
      </navigator>
      <uni-load-more :status="pageParams.isMore" />
    </view>
  </view>
</template>

<script>
import {  getDataPage } from '@/api/unloader.js';
export default {
  data() {
    return {
      lists: [],
      queryParam: {
        pageNo: 1,
        pageSize: 10
      },
      pageParams: {
        isMore: 'more'
      }
    };
  },
  onShow() {
    this.queryParam.pageNo = 1;
    this.lists = [];
    this.getList();
  },
  onPullDownRefresh() {
    this.queryParam.pageNo = 1;
    this.pageParams.isMore = 'more';
    this.lists = [];
    this.getList();
  },
  onReachBottom() {
    if (this.pageParams.isMore == 'more') {
      this.queryParam.pageNo++;
      this.getList();
    }
  },
  methods: {
    handleAdd() {
      uni.navigateTo({
        url: '/packageB/pages/common/unloader-editing/index'
      });
    },
    //获取列表
    async getList() {
      try {
        let data = {};
        Object.keys(this.queryParam).forEach((item) => {
          if (this.queryParam[item]) {
            data[item] = this.queryParam[item];
          }
        });
        let res = await getDataPage(data);
        if (res.code == 0) {
          this.lists = [...this.lists, ...res.data.list];
          if (res.data.total == this.lists.length) {
            this.pageParams.isMore = 'noMore';
          } else {
            this.pageParams.isMore = 'more';
          }

        }
        //停止下拉刷新
        wx.hideNavigationBarLoading();
        //停止下拉刷新
        wx.stopPullDownRefresh();
      } catch (e) {
        console.log('getVehicle: ', e);
        return false;
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.cph1 {
  flex: 1;
  font-weight: bold;
  font-size: 32rpx;
  padding-left: 20rpx;
  display: block;          /* 确保 text 占据一行 */
  width: 100%;             /* 或者指定一个具体宽度 */
  white-space: nowrap;     /* 不换行 */
  overflow: hidden;        /* 隐藏溢出内容 */
  text-overflow: ellipsis; /* 超出显示 ... */
}
</style>
